package com.ele.Servlet;

import com.ele.Pojo.Employee;
import com.ele.Service.impl.EmployeeServiceImpl;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
//emp
@WebServlet("/All")
public class EmpAllServlet extends HttpServlet {
    //创建service对象
    EmployeeServiceImpl employeeService = new EmployeeServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Employee> employees =employeeService.getAll();
        Gson gson = new Gson();
        String json =gson.toJson(employees);
        //
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }

}
